package com.hzdesk.media.koreabatchmatvector.contral;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.util.Log;

import com.hzdesk.media.koreabatchmatvector.base.MyClientApplication;
import com.hzdesk.media.koreabatchmatvector.bean.PathBean;
import com.hzdesk.media.koreabatchmatvector.bean.SerPath;
import com.hzdesk.media.koreabatchmatvector.bean.SerPoint;
import com.hzdesk.media.koreabatchmatvector.config.AppConfig;
import com.hzdesk.media.koreabatchmatvector.inter.ISketchpadDraw;

import java.util.Date;

/**
 * 
 * @author Mr.Lee
 *
 */
public class LineCtl implements ISketchpadDraw {

	private Paint mPaint=new Paint();
    private boolean m_hasDrawn = false;  
    private float startx = 0;  
    private float starty = 0;  
    private float endx = 0;  
    private float endy = 0;  
    private Path path,mPath;
    private boolean status=false;
    private String color;
	private int	size;
    private SerPath mCurPath;
    private long time;
    private int num;
    private Context mContext;
    public LineCtl(int penSize, String penColor,Context context)
    {
    	mContext=context;
    	mPaint.setAntiAlias(true);
        mPaint.setDither(true);
        mPaint.setColor(Color.parseColor("#"+penColor));
        mPaint.setStyle(Paint.Style.STROKE);
        mPaint.setStrokeJoin(Paint.Join.ROUND);
        mPaint.setStrokeCap(Paint.Cap.ROUND);
        mPaint.setStrokeWidth(penSize);
        this.color=penColor;
        this.size=penSize;
        path=new Path();
    }
    public LineCtl(Paint paint , Path path) {
    	mPaint=paint;
    	mPath=path;
    	status=true;
	}
    public LineCtl(Paint paint) {
    	mPaint=paint;
	}
	
	public void draw(Canvas canvas) {
		if (status) {
			canvas.drawPath(mPath, mPaint);
			mPath=null;
			status=false;
		}
		if (null != canvas)
        {	
			canvas.drawLine(startx,starty,endx,endy, mPaint); 
			//path.moveTo(startx, starty);
			//path.lineTo(endx, endy);
        }
	}
	public boolean hasDraw() {
		return m_hasDrawn;
	}
	public void cleanAll() {
	}	
	public void touchDown(float x, float y) {
		startx=x;
		starty=y;
		endx=x;
		endy=y;
		num++;
		if (MyClientApplication.isRecording()) {
			time=getTime();
			mCurPath=new SerPath();
			mCurPath.mPoints.add(new SerPoint(x, y));
			mCurPath.mTimes.add(getTime());
		}
	}
	public void touchMove(float x, float y) {
		endx=x;
		endy=y;
		num++;
		if (MyClientApplication.isRecording()) {
			mCurPath.mPoints.add(new SerPoint(x, y));
			mCurPath.mTimes.add(getTime());
		}
		m_hasDrawn=true;
	}
	public void touchUp(float x, float y) {
		endx=x;
		endy=y;
		num++;
		Log.d("Line", "size:"+num);
		if (MyClientApplication.isRecording() && MyClientApplication.getMouseUserDeviceinfoBean(mContext,MyClientApplication.getUserNum()).getDisMouse()!=1) {
			mCurPath.mPoints.add(new SerPoint(x, y));
			mCurPath.mTimes.add(getTime());
			Log.d("Line", "size:"+mCurPath.mPoints.size());
			MyClientApplication.setmPathBeanList(new PathBean(time, AppConfig.PAINT_LINE, color, size, mCurPath, MyClientApplication.getUserNum()));
		}
	}
	public long getTime() {
		return new Date().getTime() - MyClientApplication.getStartTime();
	}


}
